题意:说一句话,系统进行回复。周期N = 1999,每次遍历一遍字符串(字长不够N,从头循环),找到第N个剔除。找到最后一次剩余的字符。
1.若为‘?’,输出Yes
2.若为‘ ‘,输出No
3.其余情况,输出No comments
样例:
input | output |
---|---|
Does the jury of this programming contest use the algorithm described in this problem to answer my questions? | Yes |
At least, will anybody READ my question? | No |
This is UNFAIR! | No comments |
#include<iostream>
#include<cstdio>
using namespace std;
char str[30003];
int fun(int m,int k,int i)//以k为周期,m长度,第i次,输出的编号(0,1,2,...,m-1)
{
if(i==1)
return (m+k-1)%m;
else
return (fun(m-1,k,i-1)+k)%m;
}
int main()
{
//freopen("in.txt","r",stdin);
int len=0;
while(scanf("%c",&str[0])!=EOF)
{
if(str[0]>=' ')
{
str[++len]=str[0];//printf(" c = %c\n",str[0]);
}
}
int k=fun(len,1999,len) +1;
//printf("str[%d] = %c\n",k,str[k]);
if (str[k]=='?')
printf("Yes\n");
else if (str[k]==' ')
printf("No\n");
else
printf("No comments\n");
return 0;
}